﻿CREATE VIEW dbo.v_PurchaseContract_20
AS
SELECT     LoanID, ContractHolder, ContractHolderID, DownPayment, DownPayment_Min, DownPaymentRatio, AmountFinanced, AF_Adjusted, AFRatio_Max, 
                      AF_MaxByBookValue, SalesPrice, SellPriceRatio_Max, SellPrice_MaxByBookValue, AF_Max, Overage_AF_Max, 
                      CASE WHEN AF_Adjusted - AF_MaxByBookValue > OverageAllowed THEN AF_Adjusted - AF_MaxByBookValue ELSE 0 END + CASE WHEN SalesPrice - SellPrice_MaxByBookValue
                       > OverageAllowed THEN SalesPrice - SellPrice_MaxByBookValue ELSE 0 END AS Overage, 
                      CASE WHEN AF_Adjusted - AF_MaxByBookValue > OverageAllowed THEN AF_Adjusted - AF_MaxByBookValue ELSE 0 END AS Overage_AF, 
                      CASE WHEN SalesPrice - SellPrice_MaxByBookValue > OverageAllowed THEN SalesPrice - SellPrice_MaxByBookValue ELSE 0 END AS Overage_SP, 
                      LoanTerm, Term_Max, APR, APR_Min, Payment, PaymentPerMonth, NumberOfPayments, PaymentsPerYear, TotalPayments, 
                      dbo.PMT_New(AmountFinanced, NumberOfPayments, APR_Min, PaymentsPerYear) * NumberOfPayments AS TotalPayments_Min, ModelAge, 
                      BookValue, BookValueDesc, MilesPerYear, MileagePerYear_Max, Miles_Max, Advance, OverageFeeRatio, OverageAllowed, 
                      dbo.MinNum(AmountFinanced * FeeRate / 100, Fee_Max) AS Fee, FeeRate, Fee_Max, PTI_Max, PTI, DTI_Max, DTI, OtherFeeName, OtherFeeValue, 
                      RecourseMonths, AddMosRecourse, DeductFeeFromReserve, GrossIncome, NonEmploymentIncome, DebtNoCar, HousePayment, Installment, 
                      Revolving, JobTime_Min, ResidenceTime_Min, AreaTime_Min, MonthsCurrent, MonthsInArea, CurrPrevDistance, ModelAge_Max, JobTimeCurrent, 
                      ISNULL(SIGN(Term_Max - LoanTerm), - 1) AS LoanTermOK, CONVERT(int, ISNULL(SIGN(DownPaymentRatio - DownPayment_Min), - 1)) 
                      AS DownPaymentOK, CONVERT(int, ISNULL(SIGN(APR - APR_Min), - 1)) AS APR_OK, ISNULL(SIGN(MileagePerYear_Max - MilesPerYear), - 1) 
                      AS MilesPerYearOK, ISNULL(SIGN(DTI_Max - DTI), - 1) AS DTI_OK, ISNULL(SIGN(PTI_Max - PTI), - 1) AS PTI_OK, 
                      ISNULL(SIGN(ModelAge_Max - ModelAge), - 1) AS ModelAgeOK, ISNULL(SIGN(MonthsCurrent - ResidenceTime_Min), - 1) AS ResidenceTimeOK, 
                      ISNULL(SIGN(JobTimeCurrent - JobTime_Min), - 1) AS JobTimeOK, OpenUnitsAdjusted, OpenUnitsOK, StatusID, ContactName, ContactPhone, 
                      ContactEmail, ContactFax, ContractHolderStreet, ContractHolderCity, ContractHolderState, ContractHolderZip, ContractHolderStateName, AgreementDay, 
                      CONVERT(bit, TrackerTypeID) * TrackerReward AS TrackerReward, ServiceContract_Max, ServiceContract, ServiceContractOK, FirstName, LastName, 
                      PurchaseBatchID, IsSUV, TrackerTypeID, DealerID, Mileage, GAP, IsIndependent, AddOnRateByPayment, PLTV
FROM         dbo.v_PurchaseContract_10


GO
EXECUTE sp_addextendedproperty @name = N'MS_DiagramPane1', @value = N'[0E232FF0-B466-11cf-A24F-00AA00A3EFFF, 1.00]
Begin DesignProperties = 
   Begin PaneConfigurations = 
      Begin PaneConfiguration = 0
         NumPanes = 4
         Configuration = "(H (1[33] 4[27] 2[20] 3) )"
      End
      Begin PaneConfiguration = 1
         NumPanes = 3
         Configuration = "(H (1[43] 4[47] 3) )"
      End
      Begin PaneConfiguration = 2
         NumPanes = 3
         Configuration = "(H (1 [50] 2 [25] 3))"
      End
      Begin PaneConfiguration = 3
         NumPanes = 3
         Configuration = "(H (4 [30] 2 [40] 3))"
      End
      Begin PaneConfiguration = 4
         NumPanes = 2
         Configuration = "(H (1[56] 3) )"
      End
      Begin PaneConfiguration = 5
         NumPanes = 2
         Configuration = "(H (2 [66] 3))"
      End
      Begin PaneConfiguration = 6
         NumPanes = 2
         Configuration = "(H (4[50] 3) )"
      End
      Begin PaneConfiguration = 7
         NumPanes = 1
         Configuration = "(V (3))"
      End
      Begin PaneConfiguration = 8
         NumPanes = 3
         Configuration = "(H (1[56] 4[18] 2) )"
      End
      Begin PaneConfiguration = 9
         NumPanes = 2
         Configuration = "(H (1[43] 4) )"
      End
      Begin PaneConfiguration = 10
         NumPanes = 2
         Configuration = "(H (1[66] 2) )"
      End
      Begin PaneConfiguration = 11
         NumPanes = 2
         Configuration = "(H (4 [60] 2))"
      End
      Begin PaneConfiguration = 12
         NumPanes = 1
         Configuration = "(H (1) )"
      End
      Begin PaneConfiguration = 13
         NumPanes = 1
         Configuration = "(V (4) )"
      End
      Begin PaneConfiguration = 14
         NumPanes = 1
         Configuration = "(V (2))"
      End
      ActivePaneConfig = 13
   End
   Begin DiagramPane = 
      PaneHidden = 
      Begin Origin = 
         Top = 0
         Left = 0
      End
      Begin Tables = 
         Begin Table = "v_PurchaseContract_10"
            Begin Extent = 
               Top = 0
               Left = 1
               Bottom = 491
               Right = 207
            End
            DisplayFlags = 280
            TopColumn = 61
         End
      End
   End
   Begin SQLPane = 
      PaneHidden = 
   End
   Begin DataPane = 
      PaneHidden = 
      Begin ParameterDefaults = ""
      End
      Begin ColumnWidths = 59
         Width = 284
         Width = 705
         Width = 960
         Width = 1560
         Width = 1125
         Width = 1500
         Width = 1500
         Width = 900
         Width = 1620
         Width = 1500
         Width = 810
         Width = 900
         Width = 930
         Width = 1110
         Width = 825
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500
         Width = 1500', @level0type = N'SCHEMA', @level0name = N'dbo', @level1type = N'VIEW', @level1name = N'v_PurchaseContract_20';


GO
EXECUTE sp_addextendedproperty @name = N'MS_DiagramPane2', @value = N'Width = 1500
         Width = 1500
      End
   End
   Begin CriteriaPane = 
      Begin ColumnWidths = 11
         Column = 7845
         Alias = 2235
         Table = 1935
         Output = 720
         Append = 1400
         NewValue = 1170
         SortType = 1350
         SortOrder = 1410
         GroupBy = 1350
         Filter = 1350
         Or = 1350
         Or = 1350
         Or = 1350
      End
   End
End', @level0type = N'SCHEMA', @level0name = N'dbo', @level1type = N'VIEW', @level1name = N'v_PurchaseContract_20';


GO
EXECUTE sp_addextendedproperty @name = N'MS_DiagramPaneCount', @value = 2, @level0type = N'SCHEMA', @level0name = N'dbo', @level1type = N'VIEW', @level1name = N'v_PurchaseContract_20';

